define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'lock'], function ($, undefined, Frontend, Form, Template, undefined) {
    var validatoroptions = {
        invalid: function (form, errors) {
            $.each(errors, function (i, j) {
                Layer.msg(j);
            });
        }
    };
    var Controller = {
        index: function () {

            $('.gzt_head .text .icon').click(function () {
                var div_box = $(this).parents('.text');
                if (div_box.hasClass('hide1')) {
                    div_box.removeClass('hide1').find('.gz_num').text($(this).data('value'));
                } else {
                    div_box.addClass('hide1').find('.gz_num').text('****');
                }
            });
            var postform = $('#post-form');
            var dtpicker = new mui.DtPicker({
                type: 'month', //设置日历初始化
                beginYear: 2020, //设置开始日期
                endDate: new Date //设置结束日期
            });
            dtpicker.setSelectedValue(Config.month);
            $(document).on('click', "#rl_but", function (event) {
                var that = this;
                dtpicker.show(function (e) {
                    $('#rl_text').text(e.y.text + '年' + e.m.text + '月');
                    postform.find('input[name=month]').val(e.value);
                    postform.submit();
                }, false)
            });

            var poppicker = new mui.PopPicker();
            poppicker.setData(Config.years);
            // poppicker.setSelectedValue(Config.year);
            $(document).on('click', '#year_but', function () {
                poppicker.show(function (e) {
                    $('#year_text').text(e[0].text + '年');
                    postform.find('input[name=year]').val(e[0].text);
                    postform.submit();
                }, false);
            });
        },

        detail: function () {

            $(document).on('click', '.f_item_title', function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active').siblings('.item_list').removeClass('show')
                } else {
                    $(this).addClass('active').siblings('.item_list').addClass('show')
                }
            });

            $(document).on('click', '.qr_but', function () {
                var data = {month: $(this).data('month')};
                Fast.api.ajax({
                    url: 'index/detail',
                    data: data
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    $('.qr_but').closest('li').remove();
                    $('.mui-table-view-cell').removeClass('mui-col-xs-6').addClass('mui-col-xs-12');
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

        },

        feedback: function () {

            var postform = $('#post-form');
            postform.data("validator-options", validatoroptions);
            Form.api.bindevent(postform, function (data, ret) {
                Layer.msg(ret.msg);
                window.location.reload();
                return false;
            }, function (data, ret) {
                Layer.msg(ret.msg);
                return false;
            });

        },

        my_feedback: function () {
            $(document).on('click', '.list_title', function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active').siblings('.list_content').removeClass('show');
                } else {
                    $(this).addClass('active').siblings('.list_content').addClass('show');
                }
            });
        },

        my_payslip: function () {
            $(document).on('click', '.f_item_title', function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active').siblings('.item_list').removeClass('show');
                } else {
                    $(this).addClass('active').siblings('.item_list').addClass('show');
                }
            })
        },

        my_repassword: function () {
            load_canvas(2);
        },

        check_point: function () {
            load_canvas(1);

            $(document).on('click', '.btn_reset', function () {
                Layer.confirm('确定要发起重置识别码的申请吗？', {icon: 3, closeBtn: 0, btn: ['申请', '取消']}, function () {
                    Fast.api.ajax({
                        url: 'index/reset_pwd',
                        data: {}
                    }, function (data, ret) {
                        Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });
        },

        set_point: function () {
            load_canvas(2);
        }
    };
    return Controller;
});
